/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.renderedideas.jailescape;

import com.renderedideas.gamemanager.GameManager;
import com.renderedideas.gamemanager.GameView;
import com.renderedideas.gamemanager.Point;
import com.renderedideas.platform.Bitmap;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author RenderedIdeas
 */
public class HelpView extends GameView
{

        private Bitmap helpscreen1, helpscreen2, backButton, nextButton,transparentImage;
        private boolean shownextpage;
        Point help1, help2, back, next;

        HelpView()
        {
                helpscreen1 = new Bitmap("/images/helpscreen/helpscreen1.png");
                helpscreen2 = new Bitmap("/images/helpscreen/helpscreen2.png");
                backButton = new Bitmap("/images/menu/back.png");
                nextButton = new Bitmap("/images/menu/next.png");
                transparentImage= new Bitmap("/images/menu/trans20.png");
                help1 = new Point(0, 0);
                help2 = new Point(GameManager.screenWidth, 0);
                back = new Point(0, GameManager.screenHeight - backButton.getHeight());
                next = new Point(GameManager.screenWidth - nextButton.getWidth(), GameManager.screenHeight - nextButton.getHeight());
        }

        public void update(float deltaTime)
        {
                if (shownextpage)
                {
                        help2.x -= 16;
                        help1.x -= 16;
                }
                if (help1.x <= -GameManager.screenWidth)
                {
                        help1.x = GameManager.screenWidth;
                        shownextpage = false;
                }
                else if (help2.x <= -GameManager.screenWidth)
                {
                        help2.x = GameManager.screenWidth;
                        shownextpage = false;
                }
        }

        public void paint(Graphics g)
        {
                Bitmap.drawBitmap(g, helpscreen1, help1.x, help1.y);
                Bitmap.drawBitmap(g, helpscreen2, help2.x, help2.y);
                Bitmap.drawBitmap(g, transparentImage, 0, 0);
                Bitmap.drawBitmap(g, backButton, back.x, back.y);
                Bitmap.drawBitmap(g, nextButton, next.x, next.y);
        }

        public void keyPressed(int keyID)
        {
                if (keyID == Constants.LEFTSOFT_KEY)
                {
                        if (Game.isSoundEnabled&& Game.clickSound != null)
                        {
                                Game.clickSound.play();
                        }
                        Game.changeView(Constants.VIEW_MENUVIEW);
                }
                else if (keyID == Constants.RIGHTSOFT_KEY)
                {
                        if (Game.isSoundEnabled&& Game.clickSound != null)
                        {
                                Game.clickSound.play();
                        }
                        shownextpage = true;
                }
        }

        public void keyReleased(int keyID)
        {
        }

        public void keyRepeated(int keyID)
        {
        }

        public void pointerPressed(int pointerID, int x, int y)
        {
                if (x > back.x && x < back.x + backButton.getWidth()*3
                        && y > back.y -backButton.getHeight()&& y < back.y + backButton.getHeight())
                {
                        if (Game.isSoundEnabled&& Game.clickSound != null)
                        {
                                Game.clickSound.play();
                        }
                        Game.changeView(Constants.VIEW_MENUVIEW);
                }
                else if (x > next.x-nextButton.getWidth() && x < next.x + nextButton.getWidth()
                        && y > next.y-nextButton.getHeight()&& y < next.y + nextButton.getHeight())
                {
                        if (Game.isSoundEnabled&& Game.clickSound != null)
                        {
                                Game.clickSound.play();
                        }
                        shownextpage = true;
                }
        }

        public void pointerReleased(int pointerID, int x, int y)
        {
        }

        public void pointerDragged(int pointerID, int x, int y)
        {
        }

        public void onBackKey()
        {
                Game.changeView(Constants.VIEW_MENUVIEW);
        }

        public void handleSwipe(int direction)
        {
                if (direction == Constants.LEFTSWIPE)
                {
                        shownextpage = true;
                }
        }

        public void pause()
        {
        }

        public void resume()
        {
        }

        public void deallocate()
        {
                helpscreen1 = helpscreen2 = null;
                back = next = help1 = help2 = null;
                backButton = nextButton = null;
                transparentImage = null;
                shownextpage = false;
        }

        public void accelerometerData(double x, double y, double z, double min, double max)
        {
        }

}
